package tcc.resources;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import tcc.model.entities.VertexEntity;
import tcc.model.entities.EdgeEntity;
import tcc.model.entities.MacroProdutoEntity;
import tcc.model.entities.ProdutoEntity;

/**
 * Provides the Hibernate configurations
 * @author Gabriel Pacheco
 *
 */
@SuppressWarnings("deprecation")
public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	private static final String packageName = "tcc.model.entities"; 
	
	static {
		try {
			sessionFactory = new AnnotationConfiguration().configure()
								.addPackage(packageName)
								.addAnnotatedClass(VertexEntity.class)
								.addAnnotatedClass(EdgeEntity.class)
								.addAnnotatedClass(MacroProdutoEntity.class)
								.addAnnotatedClass(ProdutoEntity.class)
								.buildSessionFactory();
		}catch(HibernateException e) {
			System.err.println("Initial SessionFactory creation failed. " + e);
			throw new ExceptionInInitializerError(e);
		}
	}

	public static SessionFactory getSessionfactory() {
		return sessionFactory;
	}
	
}
